﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Base;
public partial class admin_Advertisement_advertisementAdd : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckRights("Basic", "B1");
        if (!this.IsPostBack)
        {
            btn_confim.Attributes.Add("onclick", "return UserAd();");
            Btn_upload.Attributes.Add("onclick", "return di();");
            DataBindAdPlaceName();
        }
    }

    private void DataBindAdPlaceName()
    {
        string strWhere = "where 1=1";
        DAL.Ad.AdPlaceManage adi = new DAL.Ad.AdPlaceManage();
        DataTable table = adi.SelctAdInfo(strWhere);
        for (int i = 0; i < table.Rows.Count; i++)
        {
            this.DropDownList1.Items.Add(new ListItem(table.Rows[i]["Ad_Name"].ToString(), table.Rows[i]["T_ID"].ToString()));
        }

    }
    protected void btn_confim_Click1(object sender, EventArgs e)
    {
        string tid = this.DropDownList1.SelectedValue;
        int Tid = Convert.ToInt32(tid);
        string isum = "管理员";
        string magid = Session["ManagerID"].ToString();
        int managerId = Convert.ToInt32(magid);
        string LoinName = Session["ManagerName"] as string;
        Model.Ad.AdMemberInfo adm = new Model.Ad.AdMemberInfo();
        adm.MImageAdrees = this.TxB_Image.Text.ToString().Trim();
        adm.M_Adrees = this.TxB_Adrees.Text.ToString().Trim();
        adm.MDay = Convert.ToInt32(this.TxB_Day.Text.ToString().Trim());
        adm.MLeter = this.TxB_word.Text.ToString().Trim();
        adm.Ad_MemberInfo_Name = this.txt_AdMName.Text.ToString().Trim();
        DAL.Ad.MemberInfo md = new DAL.Ad.MemberInfo();
        md.AddMemberAdInfo(Tid, managerId, isum, LoinName, adm);


        Response.Write("<script>alert('添加成功');location.href='AdvertisementList.aspx';</script>");
    }
    #region 上传图片
    protected void Btn_up_Click(object sender, EventArgs e)
    {
        Base.Core.WebConfig web = new Base.Core.WebConfig();
        string imgsFolder = web.ImgFolder;
        string datatime = System.DateTime.Now.ToString("yyyyMMddHHmmssffff");
        if (this.upfile_href.HasFile)
        {
            string fileName = this.upfile_href.FileName;
            string fileExition = System.IO.Path.GetExtension(fileName).ToLower();
            string de = "|.gif|.png|.jpeg|.jpg";
            string strDay = System.DateTime.Now.ToString("yyyyMM");
            string path = HttpContext.Current.Server.MapPath("/" + imgsFolder + "/" + strDay + "/");
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            if (fileName == "")
            {
                Response.Write("<script>alert('请选择上传的图片');</script>");
                return;
            }
            if (de.IndexOf(fileExition) > 0)
            {
                string NewFileName = datatime + fileExition;
                this.upfile_href.PostedFile.SaveAs(path + NewFileName);
                this.TxB_Image.Text = "/" + imgsFolder + "/" + strDay + "/" + NewFileName;
            }
            else
            {
                Response.Write("<script>alert('上传图片格式错误');</script>");
            }
        }
    }
    #endregion
}
